﻿using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PowerBooking.RSE.Utility.Helpers
{
    public class CommonHelper
    {
        public static List<List<T>> ConvertListToGroup<T>(List<T> source, int groupMemberCount)
        {
            var group = new List<List<T>>();
            for (var i = 0; i < source.Count; i = i + groupMemberCount)
            {

                group.Add(source.GetRange(i, source.Count - i < groupMemberCount ? (source.Count - i) : groupMemberCount));
            }
            return group;
        }

        public static List<KeyValuePair<int, int>> SplitNumberToRangeGroup(int number, int groupRange)
        {
            var list = new List<KeyValuePair<int, int>>();

            for (var i = 0; i < number; i = i + groupRange)
            {
                if (i + groupRange <= number)
                {
                    list.Add(new KeyValuePair<int, int>(i, i + groupRange));
                }
                else
                {
                    list.Add(new KeyValuePair<int, int>(i, number - i));
                }
            }

            return list;
        }
    }
}
